<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>网络调查</title>
		<%@ include file="../../common/Admin-list.jsp"%>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/gray/easyui.css"/>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/icon.css"/>   
		<script type="text/javascript" src="<%=basePath %>JS/jquery/jquery-1.7.1.min.js"></script>     
		<script type="text/javascript" src="<%=basePath %>easyui/jquery.easyui.min.js"></script>
	
 		<script type="text/javascript">
			$(function(){
				$('#dataGridSys').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../networkSurvey/listData.json',
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行	
					onClickRow: function (rowIndex, rowData) {
						var post= $('#dataGridSys').datagrid('getSelections');
						lodTree(post[0].id);
	                  },
					toolbar: [
						{
							text: '添加',
							iconCls: 'icon-add',
							handler: function(){	
								art.dialog.open('../networkSurvey/addInterface.htm',{
											title: '',
											id:'addDialog',
											lock:true,
										  	width: '30%',
										    height: '40%'												   												   
										});
							}
						}, '-', 
					    {
			                text : '刷新',
			                iconCls : 'icon-reload',
			                handler : function() {
			                	$('#dataGridSys').datagrid('reload');
		                }
					}],	
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'topic',title:'主题',width:120,align:'center',editor:{type:'text'}},
								{field:'beginTime',title:'开始时间',width:50,align:'center',editor:{type:'text'},
									 formatter:function(value,row,index){
										
										return value;
									} 
								},
								{field:'endTime',title:'结束时间',width:50,align:'center',editor:{type:'text'}},
							
								{field:'opt',title:'操作',width:50,align:'left',  
				                    formatter:function(value,rec,index){
		                    				var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                        
				                                                 
				                        return edit+dele ;  
				                    }  
				                 }								
					        ]]	
				});	
			})
			
			function edit(index){  //编辑   
				art.dialog.open('../networkSurvey/updateInterface.htm?opType=edit&id='+index,{
					title: '',
					id:'editDialog',
					lock:true,
				  	width: '30%',
				    height: '40%'												   												   
				});
          	}
			

			
			function del(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../networkSurvey/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									$('#dataGridSys').datagrid('reload');
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
		
			function refresh()
			{
				$('#dataGridSys').datagrid('reload');
			}
			
			
			<!---加载题目树.-->
			function lodTree(survey_id)
			{
				$('#titlett').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../networkSurveyContent/listData.json?survey_id='+survey_id,
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行	
					onClickRow: function (rowIndex, rowData) {
						var post= $('#titlett').datagrid('getSelections');
						
						loadContrentMsgTree(post[0].id);
	                  },
					toolbar: [
					{
							text: '添加',
							iconCls: 'icon-add',
							handler: function(){	
								art.dialog.open('../networkSurveyContent/addInterface.htm?survey_id='+survey_id,{
											title: '',
											id:'addContentDialog',
											lock:true,
										  	width: '30%',
										    height: '40%'												   												   
										});
							}
						}, '-', 
					    {
			                text : '刷新',
			                iconCls : 'icon-reload',
			                handler : function() {
			                	$('#titlett').datagrid('reload');
		                }
					}],	
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'content',title:'题目',width:100,align:'center',editor:{type:'text'}},
								{field:'content_type',title:'题目类型',width:100,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value=='0')
											{
												return "单选题";
											}
										else if(value=='1')
											{
												return "多选题";
											}
										else
											{
												return "简答题";
											}
									}
								},
								{field:'opt',title:'操作',width:50,align:'left',  
				                    formatter:function(value,rec,index){
		                    			var edit='<a title="编辑" onclick="editContent(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                        var dele='<a title="删除" onclick="delContent(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                                         
				                        var add='<a title="添加内容" onclick="addmsg(\''+ rec.id +'\')"  href="#">'+
					                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/add.gif" alt="Delete"></a>&nbsp;&nbsp;';
				                        return edit+dele+add ;  
				                    }  
				                 }								
					        ]]	
				});	
			}
			
			
			function loadContrentMsgTree(parent_id)
			{
				$('#msgtt').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../networkSurveyContent/listData.json?parent_id='+parent_id,
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行	
					onClickRow: function (rowIndex, rowData) {
						var post= $('#msgtt').datagrid('getSelections');
						//alert(post[0].id);
	                  },
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'content',title:'题目选项',width:100,align:'center',editor:{type:'text'}},
								{field:'opt',title:'操作',width:50,align:'left',  
				                    formatter:function(value,rec,index){
		                    				var edit='<a title="编辑" onclick="editContentMsg(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                        var dele='<a title="删除" onclick="delContentMsg(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                                         
						               
				                        return edit+dele;  
				                    }  
				                 }								
					        ]]	
				});	
			}
			
			function editContent(index){  //编辑   
				art.dialog.open('../networkSurveyContent/updateInterface.htm?opType=edit&id='+index,{
					title: '编辑主题',
					id:'editContentDialog',
					lock:true,
				  	width: '30%',
				    height: '40%'												   												   
				});
          	}
			
			
	
			
			function delContent(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../networkSurveyContent/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									$('#titlett').datagrid('reload');
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
			
			function refreshContent()
			{
				$('#titlett').datagrid('reload');
			}
			
			
			
			function addmsg(index){  //添加 
				art.dialog.open('../networkSurveyContent/addMsgInterface.htm?opType=edit&parent_id='+index,{
					title: '添加选项',
					id:'addMsgDialog',
					lock:true,
				  	width: '30%',
				    height: '40%'												   												   
				});
          	}
			
			function editContentMsg(index){  //编辑   
				art.dialog.open('../networkSurveyContent/updateContentMsgInterface.htm?opType=edit&id='+index,{
					title: '',
					id:'editContentMsgDialog',
					lock:true,
				  	width: '30%',
				    height: '40%'												   												   
				});
          	}
			
			
			
			function delContentMsg(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../networkSurveyContent/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									$('#msgtt').datagrid('reload');
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
			
			
			function refreshContentMsg()
			{
				$('#msgtt').datagrid('reload');
			}
		</script>	
	</head>
	<body>
		<div>			
			<div id="tab">
        		<ul>
            		<li class="Current">
            			<a href="#"><span>网络调查</span></a>
            		</li>
            	</ul>
    		</div>

			<div id="content" style="display: inline;">
				<div id="subject" style="float: left;"> <!-- 主题 -->
					<table id="dataGridSys"  style="width: 350px;"></table>
				</div>
				<div id="title" style="float:left;">  <!-- 题目 -->
					<table id="titlett" style="width:650px;"></table>
				</div>
				
				<div id="msg" style="float: left;">
					<table id="msgtt" style="width:100%;"></table>
				</div>
			</div>
		</div>
	</body>
</html>